<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org">
<head>
    <link rel="stylesheet" th:href="@{/static/element/index.css}"/>
</head>
<body>
<div id="app">
    <template>
        <el-form :model="queryForm" ref="queryForm" :inline="true">
            <el-form-item label="表名" prop="tableName">
                <el-input clearable
                          size="small"
                          @keyup.enter.native="handleQuery" v-model="queryForm.tableName"
                          placeholder="请输入表名称"></el-input>
            </el-form-item>

            <el-form-item label="表描述" prop="tableComment">
                <el-input clearable
                          size="small"
                          @keyup.enter.native="handleQuery" v-model="queryForm.tableComment"
                          placeholder="请输入表描述"></el-input>
            </el-form-item>
            <el-form-item>
                <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">查询</el-button>
                <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">清空</el-button>
            </el-form-item>
        </el-form>

        <el-row>
            <el-col>
                <el-button type="warning"
                           icon="el-icon-s-release"
                           size="mini" @click="batchHandleRemove">批量卸载
                </el-button>

                <el-button type="info"
                           icon="el-icon-delete-solid"
                           size="mini" @click="batchHandleDelete">批量删除
                </el-button>


            </el-col>
        </el-row>

        <el-table
                v-loading="loading"

                :data="tableData" row-key="id"
                :header-cell-style="{'text-align':'center','color':'grey','font-weight':'600'}"
                :cell-style="{'text-align':'center'}" border style="margin-top: 10px"
                @selection-change="handleSelectionChange"


        >
            <el-table-column
                    type="selection"
                    width="40">
            </el-table-column>
            <el-table-column prop="tableId" label="编号" width="60"></el-table-column>
            <el-table-column prop="tableName" label="表名" show-overflow-tooltip=""></el-table-column>
            <el-table-column prop="tableComment" label="表描述" show-overflow-tooltip="true"></el-table-column>
            <el-table-column prop="functionName" label="生成功能名"></el-table-column>
            <el-table-column prop="className" label="实体类名称"></el-table-column>
            <el-table-column prop="packageName" label="生成包路径" show-overflow-tooltip="true"></el-table-column>
            <el-table-column prop="functionAuthor" label="生成作者"></el-table-column>
            <el-table-column prop="createTime" label="创建时间"></el-table-column>

            <el-table-column label="操作">
                <template slot-scope="scope">

                    <el-button size="mini" type="info" icon="el-icon-s-release" @click="removeDeploy(scope.row)">卸载
                    </el-button>

                    <el-button size="mini" type="danger" icon="el-icon-delete" @click="handleDelete(scope.row)">删除
                    </el-button>


                </template>
            </el-table-column>

        </el-table>

        <el-pagination
                background
                :page-sizes="[10, 20, 30, 40,50]"
                layout="total, sizes, prev, pager, next, jumper"
                :total="total"
                :page-size.sync="pageSize"
                :current-page.sync="currentPage"
                @size-change="handleQuery"
                @current-change="handleQuery"
                style="float: right;margin-top: 10px;margin-top: 10px"
        />
    </template>
</div>
</body>
<script th:src="@{/static/js/axios.min.js}"></script>
<script th:src="@{/static/js/request.js}"></script>
<script th:src="@{/static/js/common.js}"></script>
<script th:src="@{/static/api/gen.js}"></script>
<script th:src="@{/static/js/vue.min.js}"></script>
<script th:src="@{/static/element/index.js}"></script>
<script th:src="@{/static/js/jquery.min.js}"></script>
<script th:src="@{/static/layer/layer.js}"></script>
<script>
    new Vue({
        el: '#app',
        data() {
            return {
                currentPage: 1,
                pageSize: 10,
                total: 0,
                loading: false,
                tableData: [],
                multipleSelection: [],
                button: {
                    export: false
                },
                queryForm: {
                    tableName: '',
                    tableComment: ''
                }
            }
        },
        created() {
            this.handleQuery();
            let sysButtons = JSON.parse(localStorage.getItem("mars-sysButtons"));
            this.button.export = sysButtons.indexOf("tool/table/export") > -1;
        },
        methods: {
            handleSelectionChange(val) {
                this.multipleSelection = val;
            },
            batchHandleRemove() {
                let params = this.multipleSelection.map((item) => {
                    return {
                        type: item.type,
                        menuId: item.genParentMenuId,
                        id: item.tableId,
                        tableName: new Array(item.tableName)
                    }
                })
                if (params.length === 0) {
                    this.$notify({
                        title: '失败',
                        type: 'error',
                        message: '请选择部署表',
                        duration: 2000
                    });
                    return
                }
                requests.post("/tool/table/deployRemove", params).then(res => {
                    if (res.code === '200') {
                        this.$notify({
                            title: '成功',
                            message: '卸载成功',
                            type: 'success'
                        });
                        this.handleQuery();
                    }
                })
            },
            batchHandleDelete() {
                if (this.multipleSelection.length === 0) {
                    this.$notify({
                        title: '失败',
                        message: '请选择删除行',
                        duration: 2000
                    });
                    return
                }
                deleteById('/tool/table/delete/' + this.multipleSelection.map((item) => item.tableId), this);
            },
            removeDeploy(row) {
                let params = {}
                params.type = row.genMenuType;
                let tables = []
                tables.push(row.tableName)
                params.tableName = tables;
                params.id = row.tableId;
                params.menuId = row.genParentMenuId;
                requests.post("/tool/table/deployRemove", new Array(params)).then(res => {
                    if (res.code === '200') {
                        this.$notify({
                            title: '成功',
                            message: '卸载成功',
                            type: 'success'
                        });
                        this.handleQuery();
                    }
                })
            },
            handleDelete(row) {
                deleteById('/tool/table/delete/' + row.tableId, this);
            },
            handleAdd() {

            },
            handleImportTable() {
                openMiddlePage('导入表结构', '/gen/table.html', this);
            },
            resetQuery() {
                this.queryForm = {}
                this.handleQuery()
            },
            handleAddOrUpdate(type, row) {
                openMiddlePage('修改表结构', '/gen/import-table-update.html?id=' + row.tableId, this);
            },
            deployCode(row) {
                let params = {}
                params.type = row.genMenuType;
                let tables = []
                tables.push(row.tableName)
                params.tableName = tables;
                params.menuId = row.genParentMenuId;
                requests.post("/tool/table/deploy", params).then(res => {
                    if (res.code === '200') {
                        this.$notify({
                            title: '成功',
                            message: '部署成功,自动重启中！',
                            type: 'success'
                        });
                    }
                })
            },
            handleQuery() {
                this.loading = true
                let queryParam = {}
                queryParam.pageNo = this.currentPage;
                queryParam.pageSize = this.pageSize;
                queryParam.tableName = this.queryForm.tableName;
                queryParam.tableComment = this.queryForm.tableComment;
                genTableList(queryParam).then(res => {
                    if (res.code === '200') {
                        this.tableData = res.data.list
                        this.total = Number(res.data.count);
                        this.loading = false
                    } else {
                        this.loading = false
                    }
                });
            },

        }
    });
</script>
</html>
